
Partial Class SAD_SQBlockingL
    Inherits System.Web.UI.Page

    Private Const Q As String = Chr(34)

    Private moServer As SQLAutoDocLib.Server = Nothing
    Private moDatabase As SQLAutoDocLib.Database = Nothing

    Private msDBID As String

    Private msStartDate As String
    Private msEndDate As String

    Private moData As DataTable = Nothing

    Private Const NODATA As Long = -999

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        msDBID = Request.QueryString("D")

        moDatabase = New SQLAutoDocLib.Database(msDBID)
        moDatabase.Load()

        moServer = New SQLAutoDocLib.Server(moDatabase.ServerID)
        moServer.Load()

        msStartDate = Request.QueryString("SD")
        msEndDate = Request.QueryString("ED")

        If Not IsDate(msEndDate) Then msEndDate = Now

        Dim oFactory As New SQLAutoDocLib.BlockLog_Factory
        moData = oFactory.AllDetailForPeriod(msStartDate, msEndDate, moDatabase.ID)

        AZoom.HRef = "SQBlockingE.aspx?D=" & moDatabase.ID & "&DT=" & HttpUtility.UrlEncode(CDate(msStartDate).Date)
        ARefresh.HRef = "SQBlockingL.aspx?D=" & moDatabase.ID & _
                                            "&SD=" & HttpUtility.UrlEncode(CDate(msStartDate)) & _
                                            "&ED=" & HttpUtility.UrlEncode(CDate(msEndDate))
    End Sub

    Protected Function FormLabel() As String
        Dim oFactory As New SQLAutoDocLib.ScanHistory_Factory
        Dim sCurrentScan As String = ""
        Dim sLastScan As String = ""
        oFactory.GetTimeOfLastScan(moDatabase.ID, SQLAutoDocLib.ScanSchedule.Type.BlockScan, "SQLAutoDocLib.BlockLog", sCurrentScan, sLastScan)

        Dim sValue As String = "Blocking Detail for " & moDatabase.Name & " from " & msStartDate & " to " & msEndDate & " last scan completed " & sLastScan

        If sCurrentScan > "" Then
            sValue = " scan in progress started " & sCurrentScan
        End If

        Return sValue
    End Function

    Protected Function ScanMode() As String
        Return "Size"
    End Function

    Protected Function EditMode() As String
        Return "Size"
    End Function

    Protected Function ServerID() As String
        Return moServer.ID
    End Function

    Protected Sub ShowTable()
        Dim oHTM As New StringBuilder("<table style=" & Q & "width: 515px; border-collapse: collapse; border: solid 1px grey;" & Q & ">")

        oHTM.Append("<tr style=" & Q & "height: 20px; vertical-align: bottom;" & Q & ">")
        oHTM.Append("<td style=" & Q & "width: 64px; border-bottom: solid 1px grey;" & Q & ">Type</td>")
        oHTM.Append("<td style=" & Q & "width: 64px; border-bottom: solid 1px grey;" & Q & ">SPID</td>")
        oHTM.Append("<td style=" & Q & "width: 64px; border-bottom: solid 1px grey;" & Q & ">Status</td>")
        oHTM.Append("<td style=" & Q & "width: 64px; border-bottom: solid 1px grey;" & Q & ">Host</td>")
        oHTM.Append("<td style=" & Q & "width: 64px; border-bottom: solid 1px grey;" & Q & ">Program</td>")
        oHTM.Append("<td style=" & Q & "width: 64px; border-bottom: solid 1px grey;" & Q & ">Command</td>")
        oHTM.Append("<td style=" & Q & "width: 64px; border-bottom: solid 1px grey;" & Q & ">Login</td>")
        oHTM.Append("</tr>")

        Dim bAlternatingColor As Boolean = False

        For Each oRow As DataRow In moData.Rows
 
            If bAlternatingColor = False Then
                oHTM.Append("<tr class=" & Q & "wmObjectList_T" & Q & " style=" & Q & "height:25px; vertical-align: bottom;" & Q & ">")
            Else
                oHTM.Append("<tr class=" & Q & "wmObjectList_TA" & Q & " style=" & Q & "height:25px; vertical-align: bottom;" & Q & ">")
            End If

            oHTM.Append("<td colspan=" & Q & "7" & Q & ">" & _
                "From " & oRow.Item("FromDate") & _
                " to " & oRow.Item("ToDate") & _
                "</td>")

            oHTM.Append("</tr>")

            If bAlternatingColor = False Then
                oHTM.Append("<tr class=" & Q & "wmObjectList_T" & Q & " style=" & Q & "height:15px;" & Q & ">")
            Else
                oHTM.Append("<tr class=" & Q & "wmObjectList_TA" & Q & " style=" & Q & "height:15px;" & Q & ">")
            End If

            oHTM.Append("<td style=" & Q & "vertical-align: top;" & Q & ">")
            oHTM.Append("Blocked")
            oHTM.Append("</td>")

            oHTM.Append("<td style=" & Q & "vertical-align: top;" & Q & ">")
            If Not oRow.Item("Blocked_SPID") Is System.DBNull.Value Then
                oHTM.Append(oRow.Item("Blocked_SPID"))
            Else
                oHTM.Append("&nbsp;")
            End If
            oHTM.Append("</td>")

            oHTM.Append("<td style=" & Q & "vertical-align: top;" & Q & ">")
            If Not oRow.Item("Blocked_Status") Is System.DBNull.Value Then
                oHTM.Append(oRow.Item("Blocked_Status"))
            Else
                oHTM.Append("&nbsp;")
            End If
            oHTM.Append("</td>")

            oHTM.Append("<td style=" & Q & "vertical-align: top;" & Q & ">")
            If Not oRow.Item("Blocked_HostName") Is System.DBNull.Value Then
                oHTM.Append(oRow.Item("Blocked_HostName"))
            Else
                oHTM.Append("&nbsp;")
            End If
            oHTM.Append("</td>")

            oHTM.Append("<td style=" & Q & "vertical-align: top;" & Q & ">")
            If Not oRow.Item("Blocked_ProgramName") Is System.DBNull.Value Then
                oHTM.Append(oRow.Item("Blocked_ProgramName"))
            Else
                oHTM.Append("&nbsp;")
            End If
            oHTM.Append("</td>")

            oHTM.Append("<td style=" & Q & "vertical-align: top;" & Q & ">")
            If Not oRow.Item("Blocked_Command") Is System.DBNull.Value Then
                oHTM.Append(oRow.Item("Blocked_Command"))
            Else
                oHTM.Append("&nbsp;")
            End If
            oHTM.Append("</td>")

            oHTM.Append("<td style=" & Q & "vertical-align: top;" & Q & ">")
            If Not oRow.Item("Blocked_LoginName") Is System.DBNull.Value Then
                oHTM.Append(oRow.Item("Blocked_LoginName"))
            Else
                oHTM.Append("&nbsp;")
            End If
            oHTM.Append("</td>")

            oHTM.Append("</tr>")

            If bAlternatingColor = False Then
                oHTM.Append("<tr class=" & Q & "wmObjectList_T" & Q & " style=" & Q & "height:15px;" & Q & ">")
            Else
                oHTM.Append("<tr class=" & Q & "wmObjectList_TA" & Q & " style=" & Q & "height:15px;" & Q & ">")
            End If

            oHTM.Append("<td style=" & Q & "vertical-align: top;" & Q & ">")
            oHTM.Append("Blocking")
            oHTM.Append("</td>")

            oHTM.Append("<td style=" & Q & "vertical-align: top;" & Q & ">")
            If Not oRow.Item("Blocking_SPID") Is System.DBNull.Value Then
                oHTM.Append(oRow.Item("Blocking_SPID"))
            Else
                oHTM.Append("&nbsp;")
            End If
            oHTM.Append("</td>")

            oHTM.Append("<td style=" & Q & "vertical-align: top;" & Q & ">")
            If Not oRow.Item("Blocking_Status") Is System.DBNull.Value Then
                oHTM.Append(oRow.Item("Blocking_Status"))
            Else
                oHTM.Append("&nbsp;")
            End If
            oHTM.Append("</td>")

            oHTM.Append("<td style=" & Q & "vertical-align: top;" & Q & ">")
            If Not oRow.Item("Blocking_HostName") Is System.DBNull.Value Then
                oHTM.Append(oRow.Item("Blocking_HostName"))
            Else
                oHTM.Append("&nbsp;")
            End If
            oHTM.Append("</td>")

            oHTM.Append("<td style=" & Q & "vertical-align: top;" & Q & ">")
            If Not oRow.Item("Blocking_ProgramName") Is System.DBNull.Value Then
                oHTM.Append(oRow.Item("Blocking_ProgramName"))
            Else
                oHTM.Append("&nbsp;")
            End If
            oHTM.Append("</td>")

            oHTM.Append("<td style=" & Q & "vertical-align: top;" & Q & ">")
            If Not oRow.Item("Blocking_Command") Is System.DBNull.Value Then
                oHTM.Append(oRow.Item("Blocking_Command"))
            Else
                oHTM.Append("&nbsp;")
            End If
            oHTM.Append("</td>")

            oHTM.Append("<td style=" & Q & "vertical-align: top;" & Q & ">")
            If Not oRow.Item("Blocking_LoginName") Is System.DBNull.Value Then
                oHTM.Append(oRow.Item("Blocking_LoginName"))
            Else
                oHTM.Append("&nbsp;")
            End If
            oHTM.Append("</td>")

            oHTM.Append("</tr>")

            bAlternatingColor = Not bAlternatingColor
        Next

        oHTM.Append("</table>")

        Response.Write(oHTM.ToString)
    End Sub
End Class
